package Sudoku;
import java.io.*;

public class Solution {
	public static void main(String[] args)  throws Exception{
		//BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
		BufferedReader b = new BufferedReader(new FileReader("src/Sudoku/data.txt"));
		String s[],l;
		int i,j,a[][]=new int[9][9],c[][]=new int[9][9];
		for(i=0;i<=8;i++){
			l = b.readLine();
			s=l.split(" ");
			for(j=0;j<=8;j++){
				a[i][j]=Integer.parseInt(s[j]);
				c[i][j]=a[i][j];
			}
		}
		s(0,0,a,c);

		for(i=0;i<=8;i++){
			l="";
			for(j=0;j<=8;j++)l+=a[i][j]+" ";
			System.out.println(l);
		}
	}

	static boolean s(int x,int y,int a[][],int c[][]){
		for( int k = 1 ; k <= 9; ++k ) 
		{
			int z=0,p=0;
			if(c[x][y]!=0){k=c[x][y];p=1;} 			
			for( int m = 0 ; m < 9 ; ++m ) 
				if( a[m][y] == k&&m!=x )z=1;  
			for( int n = 0 ; n < 9 ; ++n ) 
				if( a[x][n] == k&&n!=y ) z=1 ;
			for(int m=0;m<=2;m++)
				for(int n=0;n<=2;n++)
					if(a[(x/3)*3+m][(y/3)*3+n]==k&&((y/3)*3+n)!=y&&((x/3)*3+m)!=x)z=1;
			if(z==1&&p==1)break;
			if(z==1)continue;
			a[x][y] =k;
			if(x==8&&y==8)return true;
			if( y<8){
				if(s(x  , y +1,a,c ) )return true ;
			}  
			else{
				if( x<8){
					if(s(x+1  , 0,a,c ) )return true ;
				} 
			}
			if(p==1)break;
		}
		a[x][y] = c[x][y]; 
		return false;
	}
}